<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="pro_produce" :rules="rules" label-width="100px" id="mvcfm">
      <el-button @click="procedureAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/mes/product/CartogramProcedure?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
      <div class="form-unit">
        <span class="mvc-title-left"> 增加工序 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工序条形码" prop="process_barcode">
              <el-input v-model="pro_produce.process_barcode" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工序分类" prop="process_classid">
              <el-select style='width:100%' v-model="pro_produce.process_classid">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in l_class" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工序性质" prop="process_nature">
              <el-select style='width:100%' v-model="pro_produce.process_nature" @change="list_s_nature" placeholder='选择性质'>
                <el-option label="选择性质" value='' />
                <el-option v-for="dict in s_nature" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工序类型" prop="process_type">
              <el-select style='width:100%' v-model="pro_produce.process_type">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in s_pr_type" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工序名称" prop="process_name">
              <el-input v-model="pro_produce.process_name" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="变更状态" prop="process_state">
              <el-radio-group v-model="pro_produce.process_state">
                <el-radio-button label="0/A">0/A</el-radio-button>
                <el-radio-button label="1/A">1/A</el-radio-button>
                <el-radio-button label="2/A">2/A</el-radio-button>
                <el-radio-button label="3/A">3/A</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="工序描述" prop="process_des">
              <el-input type="textarea" v-model="pro_produce.process_des" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="工序管理岗位" prop="person_name">
              {{pro_produce.person_name}}
              <el-button @click="popPostSelection('person_name','process_user')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="每时能力值" prop="throughput_hour">
              <el-input v-model="pro_produce.throughput_hour" placeholder='' />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="能力单位" prop="throughput_unit">
              <el-input v-model="pro_produce.throughput_unit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="能力说明" prop="throughput_explain">
              <el-input type="textarea" v-model="pro_produce.throughput_explain" ttparea=350></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-button @click="procedureAddSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
      <el-button @click="gotoPage('/mes/product/CartogramProcedure?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>取消</el-button>
    </el-form>
    <el-dialog :visible.sync="PostSelectionVisible" append-to-body>
      <PostSelection v-if="PostSelectionVisible" ref="PostSelection" :popparams="popparams"> </PostSelection>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import PostSelection from "@/views/mes/product/PostSelection";
  export default {
    name: 'ProcedureAdd',
    components: {
      PostSelection,
    },
    props: ['popparams'],
    data() {
      return {
        PostSelectionVisible: false,
        PostSelectionValue: null,
        PostSelectionDesc: null,
        vueparams: this.getVUEParams("&CMID5=14"),
        pro_produce: {
          process_barcode: null,
          process_classid: null,
          process_nature: null,
          process_type: null,
          process_name: null,
          process_state: null,
          process_des: null,
          person_name: null,
          throughput_hour: null,
          throughput_unit: null,
          throughput_explain: null,
        },
        l_class: [],
        s_nature: [],
        s_pr_type: [],
        loading: false,
        rules: {
          process_name: [{
            required: true,
            message: "工序名称不能为空",
            trigger: 'blur',
          }],
          person_name: [{
            required: true,
            message: "工序管理岗位不能为空",
            trigger: 'change',
          }],
        }
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/product/ProcedureAction/procedureAdd?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      procedureAddSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/product/ProcedureAction/procedureAddSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/product/ProductProDet/productProDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      list_s_nature(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/product/ProcedureAction/procedureAjax?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "process_type",
            process_nature: value
          }
        }).then(data => {
          this.$set(this.pro_produce, 'process_type', '');
          this.s_pr_type = data['process_type'];
        })
      },
      popPostSelection(desc, value) {
        this.PostSelectionVisible = true;
        this.PostSelectionDesc = desc;
        this.PostSelectionValue = value;
      },
      closePostSelection(value, desc) {
        this.PostSelectionVisible = false;
        this.$set(this.pro_produce, this.PostSelectionDesc, desc);
        this.$set(this.pro_produce, this.PostSelectionValue, value);
      },
    },
  }
</script>
